const TOKENKEY = "token_key";
const USERINFO = "user";

function setToken(token) {
  return localStorage.setItem(TOKENKEY, token);
}

function getToken() {
  const token = localStorage.getItem(TOKENKEY);
  return token ? token : null;
}

function clearToken() {
  return localStorage.removeItem(TOKENKEY);
}

function getUser() {
  const user = localStorage.getItem(USERINFO);
  return user ? JSON.parse(user) : null;
}

function setUser(user) {
  return localStorage.setItem(USERINFO, JSON.stringify(user));
}

function clearUserInfo() {
  return localStorage.removeItem(USERINFO);
}

export { setToken, getToken, clearToken, getUser, setUser, clearUserInfo };
